package logic;

import global.CommandType.Type;
import global.Methods;

import java.net.URI;
import java.util.ArrayList;

public class OpenCalendarCommand extends Command{
	private String feedback;
	private boolean isExecutable;
	private String gCalUrlString;
	
	public OpenCalendarCommand(boolean executable, String feedback){
		this.feedback = feedback;
		this.isExecutable = executable;
		gCalUrlString = "http://calendar.google.com";
	}
	
	public ArrayList<String> execute(){
		ArrayList<String> newFeedback = new ArrayList<String>();
		DisplayCommand lastDisplay;
		try {
			Methods.browse(gCalUrlString);
			feedback = "Calendar successfully opened in your default browser";
			lastDisplay = ExecutionHandler.getRecentDisplay();
			newFeedback = lastDisplay.display();
			ExecutionHandler.setIsUndo(false);
		} catch (Exception e) {
			feedback = "Unable to open calendar";
			lastDisplay = ExecutionHandler.getRecentDisplay();
			newFeedback = lastDisplay.display();
			ExecutionHandler.setIsUndo(false);
			e.printStackTrace();
		}
		
		ExecutionHandler.setMostRecentCommandType(Type.OPEN);
		ExecutionHandler.setIsUndo(false);
		newFeedback.add(feedback);
		return newFeedback;
	}
	
	public String getTestFeedback() {
		return "open calendar";
	}
}
